package com.yanqu.road.server.pb;

import com.yanqu.road.entity.estatewar.palace.PalaceFloorConfig;
import com.yanqu.road.entity.estatewar.EstateWarRecord;
import com.yanqu.road.entity.estatewar.UserEstateFloor;
import com.yanqu.road.entity.estatewar.UserEstateWarData;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.estatewar.EstateWarProto;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.server.manger.ServerLanguageMgr;
import com.yanqu.road.server.manger.player.EstateWarMgr;

import java.util.List;

public class EstateWarPb {

    public static EstateWarProto.EstateWarUserDataMsg.Builder parseEstateWarUserDataMsg(UserEstateWarData userEstateWarData){
        if(null == userEstateWarData){
            return null;
        }
        EstateWarProto.EstateWarUserDataMsg.Builder msg = EstateWarProto.EstateWarUserDataMsg.newBuilder();
        msg.setType(userEstateWarData.getType());
        msg.setPos(userEstateWarData.getPos());
        msg.setCrossType(userEstateWarData.getCrossType());
        msg.setCrossPos(userEstateWarData.getCrossPos());
        msg.setWorshipValue(userEstateWarData.getWorshipValue());
        msg.setGetDailyRewardTime(userEstateWarData.getGetDailyRewardTime());
        msg.setCanWorshipValue(EstateWarMgr.getCanWorshipValue());
        msg.setEstateSkinId(userEstateWarData.getEstateSkinId());
        return msg;
    }

    public static EstateWarProto.EstateWarFloorTempMsg.Builder parseEstateWarFloorTempMsg(UserEstateFloor userEstateFloor){
        if(null == userEstateFloor){
            return null;
        }
        EstateWarProto.EstateWarFloorTempMsg.Builder msg = EstateWarProto.EstateWarFloorTempMsg.newBuilder();
        msg.setUserId(userEstateFloor.getUserId());
        msg.setType(userEstateFloor.getType());
        msg.setPos(userEstateFloor.getPos());
        PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(userEstateFloor.getUserBaseInfo());
        msg.setPlayerBaseData(baseMsg);
        msg.setTotalAbility(userEstateFloor.getTotalAbility().toString());
        return msg;
    }

    public static EstateWarProto.EstateWarFloorListMsg.Builder parseEstateWarFloorListMsg(List<UserEstateFloor> userEstateFloorList){
        EstateWarProto.EstateWarFloorListMsg.Builder listMsg = EstateWarProto.EstateWarFloorListMsg.newBuilder();
        if(null != userEstateFloorList) {
            for (UserEstateFloor userEstateFloor : userEstateFloorList) {
                EstateWarProto.EstateWarFloorTempMsg.Builder msg = parseEstateWarFloorTempMsg(userEstateFloor);
                if (null != msg) {
                    listMsg.addDataList(msg);
                }
            }
        }
        return listMsg;
    }

    public static EstateWarProto.EstateWarRecordTempMsg.Builder parseEstateWarRecordTempMsg(EstateWarRecord estateWarRecord){
        if(null == estateWarRecord){
            return null;
        }
        EstateWarProto.EstateWarRecordTempMsg.Builder msg = EstateWarProto.EstateWarRecordTempMsg.newBuilder();
        msg.setRecordUid(estateWarRecord.getRecordUid());
        msg.setIsWin(estateWarRecord.isWin());
        msg.setRecordTime(estateWarRecord.getRecordTime());
        msg.setEnemyUserId(estateWarRecord.getEnemyUserId());
        PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(estateWarRecord.getEnemyBaseData());
        msg.setEnemyBaseData(baseMsg);
        msg.setOldType(estateWarRecord.getOldType());
        msg.setOldPos(estateWarRecord.getOldPos());
        msg.setNowType(estateWarRecord.getNowType());
        msg.setNowPos(estateWarRecord.getNowPos());
        return msg;
    }

    public static EstateWarProto.EstateWarRecordListMsg.Builder parseEstateWarRecordListMsg(List<EstateWarRecord> estateWarRecordList){
        EstateWarProto.EstateWarRecordListMsg.Builder listMsg = EstateWarProto.EstateWarRecordListMsg.newBuilder();
        if(null != estateWarRecordList) {
            for (EstateWarRecord estateWarRecord : estateWarRecordList) {
                EstateWarProto.EstateWarRecordTempMsg.Builder msg = parseEstateWarRecordTempMsg(estateWarRecord);
                if (null != msg) {
                    listMsg.addDataList(msg);
                }
            }
        }
        return listMsg;
    }

    public static EstateWarProto.PalaceConfigTempMsg.Builder parsePalaceConfigTempMsg(PalaceFloorConfig data, String language){
        if(null == data){
            return null;
        }
        EstateWarProto.PalaceConfigTempMsg.Builder msg = EstateWarProto.PalaceConfigTempMsg.newBuilder();
        msg.setTitleType(data.getTitleType());
        msg.setPos(data.getPos());
        msg.setNpcName(ServerLanguageMgr.getContent(data.getNpcName(), language));
        msg.setNpcPic(data.getNpcPic());
        msg.setNpcEarnSpeed(data.getNpcEarnSpeed().toString());
        msg.setRecruitNum(data.getRecruitNum());
        msg.setRecruitReward(data.getRecruitReward());
        msg.setDailyReward(data.getDailyReward());
        msg.setSkinsReward(data.getSkinsReward());
        return msg;
    }

    public static EstateWarProto.PalaceActivityMsg.Builder parsePalaceActivityMsg(List<PalaceFloorConfig> dataList, String language){
        EstateWarProto.PalaceActivityMsg.Builder listMsg = EstateWarProto.PalaceActivityMsg.newBuilder();
        if(null != dataList){
            for(PalaceFloorConfig data : dataList){
                EstateWarProto.PalaceConfigTempMsg.Builder msg = parsePalaceConfigTempMsg(data, language);
                if(null != msg){
                    listMsg.addConfigList(msg);
                }
            }
        }
        return listMsg;
    }
}
